﻿using DGIS.Service.Model;
using ESRI.ArcGIS.Carto;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DGIS.Main.Forms.Data
{
    public partial class LayersFrm : Form
    {
        //当前选中图层名称
        public string _selectedLayerName;

        private List<DataLayer> _layers;
        
        public LayersFrm(List<DataLayer> layers)
        {
            _layers = layers;
            InitializeComponent();
        }

        private void LayersFrm_Load(object sender, EventArgs e)
        {
            foreach (var layer in _layers)
            {
                TreeNode node = BuildNode(layer);

                this.treeView.Nodes.Add(node);
            }
        }

        private TreeNode BuildNode(DataLayer layer)
        {
            TreeNode node = new TreeNode()
            {
                Text=layer.Name
            };
            if (layer.Child != null)
            {
                foreach (DataLayer pLayer in layer.Child)
                {
                    node.Nodes.Add(BuildNode(pLayer));
                }
            }

            return node;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            TreeNode node = this.treeView.SelectedNode;
            if (node.Nodes.Count == 0) {
                this._selectedLayerName = node.Text;
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("请选择一个图层");
            }
        }
    }
}
